﻿using OfficeOpenXml.Sorting;
using Prism.DryIoc;
using Prism.Ioc;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using WcsZz.Extend;
using wms_wpf.Apiservice;
using wms_wpf.DialogView;
using wms_wpf.DialogViewModel;
using wms_wpf.ViewModels;
using wms_wpf.ViewModels.ExpressChildViewModel;
using wms_wpf.Views;

namespace wms_wpf
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {



        protected override Window CreateShell()
        {


        return    Container.Resolve<MainWindow>();
          


        }
        private static System.Threading.Mutex mutex;
        protected override void OnStartup(StartupEventArgs e)
        {
            mutex = new System.Threading.Mutex(true, "WcsZz");
            if (mutex.WaitOne(0, false))
            {
                base.OnStartup(e);
            }
            else
            {
                MessageBox.Show("程序已经在运行！", "提示");
                this.Shutdown();
            }
        }

        protected override void OnInitialized()
        {
          
            var dialog = Container.Resolve<IDialogService>();
            dialog.ShowDialog("LoginView", callback =>
            {
                // 假设ButtonResult.OK意味着登录成功
                // 根据你的业务逻辑，你可以在这里决定启动哪个视图
                if (callback.Result == ButtonResult.OK) // 你需要根据实际情况替换这里的条件
                {

                    // 显示MainWindow

                    //Application.Current.MainWindow = Container.Resolve<MainWindow>();//怎么在容器里移除
                    //Application.Current.MainWindow.Show();
                    return;
                }
                else if (callback.Result == ButtonResult.Yes)
                {

                    // 显示ExpressView
                    Application.Current.MainWindow = Container.Resolve<ExpressView>();
                    Application.Current.MainWindow.Show();
                    return;
                }
                else
                {
                    Application.Current.Shutdown();

                }

            });
            base.OnInitialized();
        }
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<MainWindow, MainWindowModel>();//注册view和viewmodel
            containerRegistry.RegisterForNavigation<ExpressView, ExpressViewModel>("ExpressView");
            containerRegistry.RegisterForNavigation<HouseConfigView, HouseConfigViewModel>("HouseConfigView");
            containerRegistry.RegisterForNavigation<MaterialView, MaterialViewModel>("MaterialView");
            containerRegistry.RegisterForNavigation<BoxConfigView, BoxConfigViewModel>("BoxConfigView");
            containerRegistry.RegisterForNavigation<UserManageView, UserManageViewModel>("UserManageView");
            containerRegistry.RegisterForNavigation<OutofStockView, OutofStockViewModel>("OutofStockView");
            containerRegistry.RegisterForNavigation<TaskOrderView, TaskOrderViewModel>("TaskOrderView");
            containerRegistry.RegisterForNavigation<CusetomOrderView, CusetomOrderViewModel>("CusetomOrderView");
            containerRegistry.RegisterForNavigation<LogView, LogViewModel>("LogView");
            containerRegistry.RegisterForNavigation<Viewport3d>("Viewport3d");
            containerRegistry.RegisterForNavigation<MergeView, MergeViewModel>("MergeView");
            containerRegistry.RegisterForNavigation<Dialog1, Dialog1ViewModel>("Dialog1");
            containerRegistry.RegisterForNavigation<Dialog2, Dialog2ViewModel>("Dialog2");
            //containerRegistry.RegisterForNavigation<Dialog3, BoxConfigViewModel>("Dialog3");

            containerRegistry.RegisterDialog<Dialog3, Dialog3ViewModel>("Dialog3");


            containerRegistry.RegisterForNavigation<Dialog8, Dialog8ViewModel>("Dialog8");
            containerRegistry.RegisterDialog<DetailsDialog, DetailsDialogViewModel>();
            containerRegistry.RegisterScoped<IBaseService, BaseService>();
            containerRegistry.RegisterScoped<IViewService, ViewService>();
            containerRegistry.RegisterScoped<IEssService, EssService>();
            containerRegistry.RegisterScoped<ICustomService, CustomService>();
            containerRegistry.Register<IDialogService, DialogService>();

            containerRegistry.RegisterDialog<LoginView, LoginViewModel>();
            containerRegistry.RegisterForNavigation<LabelView>("LabelView");

        }
    }
}
